*Figure 11


use "Data_ImportantProvisions_240423.dta", clear


foreach expert in "Participant1" "Participant2" "Participant3" "Participant4" "Participant5" "Participant6" "Participant7" "Participant8" "Participant9" "Participant10" "Participant11" "Participant12"{
gen same_func_democ_`expert' = 0
gen same_new_democ_`expert' = 0
gen same_divided_democ_`expert' = 0

replace same_func_democ_`expert' = 1 if func_democ_`expert' != general_`expert'
replace same_new_democ_`expert' = 1 if new_democ_`expert' != general_`expert'
replace same_divided_democ_`expert' = 1 if divided_democ_`expert' != general_`expert'

}


*functioning democracies
preserve
keep lab same_func_democ*
xpose, clear varname
egen sum_func_democ = rowtotal(v*)
drop if _varname == "lab"
keep _varname sum_func_democ
ren _varname expert_name
replace expert_name = subinstr(expert_name, "same_func_democ_", "", .)
tempfile func_democ
save `func_democ'
restore

*new democracies
preserve
keep lab same_new_democ*
xpose, clear varname
egen sum_new_democ = rowtotal(v*)
drop if _varname == "lab"
keep _varname sum_new_democ
ren _varname expert_name
replace expert_name = subinstr(expert_name, "same_new_democ_", "", .)
tempfile new_democ
save `new_democ'
restore

*preserve
keep lab same_divided_democ*
xpose, clear varname
egen sum_divided_democ = rowtotal(v*)
drop if _varname == "lab"
keep _varname sum_divided_democ
ren _varname expert_name
replace expert_name = subinstr(expert_name, "same_divided_democ_", "", .)

merge 1:1 expert_name using `func_democ', nogen
merge 1:1 expert_name using `new_democ', nogen


gen order_ = .
replace order_ = 1 if expert_name == "Participant1"
replace order_ = 2 if expert_name == "Participant2"
replace order_ = 3 if expert_name == "Participant3"
replace order_ = 4 if expert_name == "Participant4"
replace order_ = 5 if expert_name == "Participant5"
replace order_ = 6 if expert_name == "Participant6"
replace order_ = 7 if expert_name == "Participant7"
replace order_ = 8 if expert_name == "Participant8"
replace order_ = 9 if expert_name == "Participant9"
replace order_ = 10 if expert_name == "Participant10"
replace order_ = 11 if expert_name == "Participant11"
replace order_ = 12 if expert_name == "Participant12"


*****************************
// without names
*Panel A): Functioning Democracies
graph bar sum_func_democ,  over(expert_name, label(angle(45)) sort(order_)) bar(1,color(navy)) ytitle("Count") 
graph export "Figure_11_A.pdf", replace

*Panel B): New Democracies 
graph bar sum_new_democ,  over(expert_name, label(angle(45)) sort(order_)) bar(1,color(forest_green)) ytitle("Count") 
graph export "Figure_11_B.pdf", replace

*Panel C): Divided Democracies
graph bar sum_divided_democ,  over(expert_name, label(angle(45)) sort(order_)) bar(1,color(purple)) ytitle("Count") 
graph export "Figure_11_C.pdf", replace




